<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	
	public function logoutUser(){
		//load libraries, helepers
		$this->load->library('session');
		$this->load->helper('url');
		
		$this->session->sess_destroy();
		redirect(base_url());
	}
	
	public function loginUser(){
		$this->load->model('user');
		$results = $this->user->login();
		if(sizeOf($results) == 1){
			//load libraries, helepers
			$this->load->library('session');
			$this->load->helper('url');
			
			$userLoginData = array(
				'id_node' => $results[0]->id_node,
                'name' => $results[0]->name,
				'surname' => $results[0]->surname,
				'email' => $results[0]->email,
                'logged_in' => TRUE
            );
			$this->session->set_userdata($userLoginData);
			echo '1';
		}
		else{
			echo '0';
		}
	}
}